<?php
class Apps_View_Helper_FlashMessenger extends Zend_View_Helper_Abstract {
	protected $_format = '<div class="alert alert-block %s"><a class="close fade in" data-dismiss="alert" href="##">×</a><p style="font-weight:bold;text-align:center">%s</p></div>';

	public function flashMessenger($wrapper=array('<div class="shout-box">', '</div>'), $msg=null) {
		if(!$msg) {
		    $msgr = new Zend_Controller_Action_Helper_FlashMessenger();
            $msg  = $msgr->getMessages();
		} else if(is_string($msg)) {
			$msg = array('' => $msg);
		}

		$xhtml  = '';

		if(is_array($msg)) {
			$format = $this->_format;

		    // Render
	        foreach ($msg as $cl => $ct) {
	        	if(is_array($ct)) {
		        	foreach ($ct as $c => $v) {
		        		$xhtml .= sprintf($format, $c, $v);
		        	}
	        	} else {
	                $xhtml .= sprintf($format, $cl, $ct);
	        	}
	        }

	        if(is_array($wrapper)) {
	        	$xhtml = $wrapper[0] . $xhtml . $wrapper[1];
	        }
		}
        return $xhtml;
	}
}
